import Vue from 'vue'
import Router from 'vue-router'
import ProductDetail from '../views/wms/product/product/productDetail.vue'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  {
    path: '/wms/product/product',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'productDetail/:productId',
        component: () => import('@/views/wms/product/product/productDetail'),
        name: 'productDetail',
        meta: { title: '货品详情', icon: 'user' }
      }
    ]
  },
  {
    path: '/wms/message/message',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'message',
        component: () => import('@/views/wms/message/message/index.vue'),
        name: 'message',
        meta: { title: '系统消息'}
      }
    ]
  },
  // {
  //   path: "/productDetail/:productId",
  //   name: 'ProductDetail',
  //     component: Layout,
  //     component: ()=>import('@/views/wms/product/product/productDetail')
  // }
  {
    path: '/wms/unit/suppliers',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'query/:supplierId',
        component: () => import('@/views/wms/unit/suppliers/query'),
        name: 'query',
        meta: { title: '供应商详情', icon: 'user' }
      }
    ]
  },
  {
    path: '/wms/customers/customers',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'query',
        component: () => import('@/views/wms/customers/customers/query.vue'),
        name: 'query',
        meta: { title: '客户详情', icon: 'user' }
      }
    ]
  },
  {
    path: '/wms/customers/customers',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'query',
        component: () => import('@/views/wms/customers/customers/query.vue'),
        name: 'query',
        meta: { title: '客户详情', icon: 'user' }
      }
    ]
  },
  {
    path: '/wms/transfer/transfer',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'query',
        component: () => import('@/views/wms/transfer/transfer/query.vue'),
        name: 'query',
        meta: { title: '调拨详情', icon: 'user' }
      }
    ]
  },
  {
    path: '/wms/transfer/transfer',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'query',
        component: () => import('@/views/wms/transfer/transfer/addAll.vue'),
        name: 'query',
        meta: { title: '库存添加', icon: 'user' }
      }
]
  },
  {
    path: '/inbound',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'inboundDetail/:inventoryId',
        component: ()=>import('@/views/wms/inbound/inbound/inboundDetail.vue'),
        name: 'inboundDetail',
        meta: { title: '入库详情', icon: 'user' }
      }
    ]
  },
  // {
  //   path: '/inout',
  //   component: Layout,
  //   hidden: true,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'inout',
  //       component: ()=>import('@/views/wms/inbound/inbound/inout.vue'),
  //       name: 'inout',
  //       meta: { title: '出入库流水', icon: 'user' }
  //     }
  //   ]
  // },
  // },{
  //   path: '/s',
  //   component: ()=>import('@/views/wms/message/test.vue')
  // }

]
// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  },
  {
    path: '/wms/purchase/purchase',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['purchase:purchase:add'],
    children: [
      {
        path: 'add', // 修改为相对路径
        component: () => import('@/views/wms/purchase/purchase/addorupdate.vue'),
        name: 'add',
        meta: { title: '进货订单添加', activeMenu: '/wms/purchase/purchase' },

      }
    ]
  },
  {
    path: '/wms/purchase/purchase',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['purchase:purchase:edit'],
    children: [
      {
        path: 'update', // 修改为相对路径
        component: () => import('@/views/wms/purchase/purchase/addorupdate.vue'),
        name: 'update',
        meta: { title: '进货订单修改', activeMenu: '/wms/purchase/purchase' },

      }
    ]
  },
  {
    path: '/wms/purchase/purchase',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['purchase:purchase:detail'],
    children: [
      {
        path: 'detail', // 修改为相对路径
        component: () => import('@/views/wms/purchase/purchase/detail.vue'),
        name: 'detail',
        meta: { title: '进货订单详情', activeMenu: '/wms/purchase/purchase' },

      }
    ]
  },
  {
    path: '/wms/sale/sale',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['sale:sale:detail'],
    children: [
      {
        path: 'detail', // 修改为相对路径
        component: () => import('@/views/wms/sale/sale/detail.vue'),
        name: 'detail',
        meta: { title: '销售订单详情', activeMenu: '/wms/sale/sale' },

      }
    ]
  },
  {
    path: '/wms/purchase/purchase',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['purchase:purchase:list'],
    children: [
      {
        path: 'find', // 修改为相对路径
        component: () => import('@/views/wms/purchase/purchase/index.vue'),
        name: 'find',
        meta: { title: '进货订单', activeMenu: '/wms/purchase/purchase' },

      }
    ]
  },
  {
    path: '/wms/sale/sale',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['sale:sale:list'],
    children: [
      {
        path: 'find', // 修改为相对路径
        component: () => import('@/views/wms/sale/sale/index.vue'),
        name: 'find',
        meta: { title: '销售订单', activeMenu: '/wms/sale/sale' },

      }
    ]
  },
  {
    path: '/wms/sale/sale',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['sale:sale:add'],
    children: [
      {
        path: 'add', // 修改为相对路径
        component: () => import('@/views/wms/sale/sale/addorupdate.vue'),
        name: 'add',
        meta: { title: '销售订单添加', activeMenu: '/wms/sale/sale' },

      }
    ]
  },
  {
    path: '/wms/inrejected/inrejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['inrejected:inrejected:add'],
    children: [
      {
        path: 'add', // 修改为相对路径
        component: () => import('@/views/wms/inrejected/inrejected/addorupdate.vue'),
        name: 'add',
        meta: { title: '进货退货单添加', activeMenu: '/wms/inrejected/inrejected' },

      }
    ]
  },
  {
    path: '/wms/inrejected/inrejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['inrejected:inrejected:list'],
    children: [
      {
        path: 'find', // 修改为相对路径
        component: () => import('@/views/wms/inrejected/inrejected/index.vue'),
        name: 'find',
        meta: { title: '进货退货单', activeMenu: '/wms/inrejected/inrejected' },

      }
    ]
  },
  {
    path: '/wms/rejected/rejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['rejected:rejected:list'],
    children: [
      {
        path: 'find', // 修改为相对路径
        component: () => import('@/views/wms/rejected/rejected/index.vue'),
        name: 'find',
        meta: { title: '销售退货单', activeMenu: '/wms/rejected/rejected' },

      }
    ]
  },
  {
    path: '/wms/inrejected/inrejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['inrejected:inrejected:edit'],
    children: [
      {
        path: 'update', // 修改为相对路径
        component: () => import('@/views/wms/inrejected/inrejected/addorupdate.vue'),
        name: 'update',
        meta: { title: '进货退货单修改', activeMenu: '/wms/inrejected/inrejected' },

      }
    ]
  },
  {
    path: '/wms/rejected/rejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['rejected:rejected:edit'],
    children: [
      {
        path: 'update', // 修改为相对路径
        component: () => import('@/views/wms/rejected/rejected/addorupdate.vue'),
        name: 'update',
        meta: { title: '销售退货单修改', activeMenu: '/wms/rejected/rejected' },

      }
    ]
  },
  {
    path: '/wms/rejected/rejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['rejected:rejected:add'],
    children: [
      {
        path: 'add', // 修改为相对路径
        component: () => import('@/views/wms/rejected/rejected/addorupdate.vue'),
        name: 'add',
        meta: { title: '销售退货单添加', activeMenu: '/wms/rejected/rejected' },

      }
    ]
  },
  {
    path: '/wms/rejected/rejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['rejected:rejected:detail'],
    children: [
      {
        path: 'detail', // 修改为相对路径
        component: () => import('@/views/wms/rejected/rejected/detail.vue'),
        name: 'detail',
        meta: { title: '销售退货单详情', activeMenu: '/wms/rejected/rejected' },

      }
    ]
  },
  {
    path: '/wms/inrejected/inrejected',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['inrejected:inrejected:detail'],
    children: [
      {
        path: 'detail', // 修改为相对路径
        component: () => import('@/views/wms/inrejected/inrejected/detail.vue'),
        name: 'detail',
        meta: { title: '进货退货单详情', activeMenu: '/wms/inrejected/inrejected' },

      }
    ]
  },
  {
    path: '/wms/sale/sale',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['sale:sale:edit'],
    children: [
      {
        path: 'update', // 修改为相对路径
        component: () => import('@/views/wms/sale/sale/addorupdate.vue'),
        name: 'update',
        meta: { title: '销售订单修改', activeMenu: '/wms/sale/sale' },

      }
    ]
  },
  {
    path: '/wms/check/check',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['check:check:checkadd'],
    children: [
      {
        path: 'checkadd', // 修改为相对路径
        component: () => import('@/views/wms/check/check/checkadd.vue'),
        name: 'checkadd',
        meta: { title: '盘点单新增', activeMenu: '/wms/check/check' },

      }
    ],
  },
	{
	  path: '/wms/check/check',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['check:check:index'],
	  children: [
	    {
	      path: 'index', // 修改为相对路径
	      component: () => import('@/views/wms/check/check/index.vue'),
	      name: 'index',
	      meta: { title: '库存盘点', activeMenu: '/wms/check/check' },
	    }
	  ]
	},
	{
	  path: '/wms/warehouse/warehouse',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['warehouse:warehouse:inboundadd'],
	  children: [
	    {
	      path: 'add', // 修改为相对路径
	      component: () => import('@/views/wms/warehouse/warehouse/inboundadd'),
	      name: 'add',
	      meta: { title: '仓库添加', activeMenu: '/wms/warehouse/warehouse' },

	    }
	  ]
	},
	{
	  path: '/wms/warehouse/warehouse',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['warehouse:warehouse:warehouseDetails'],
	  children: [
	    {
	      path: 'details', // 修改为相对路径
	      component: () => import('@/views/wms/warehouse/warehouse/warehouseDetails'),
	      name: 'details',
	      meta: { title: '仓库添加', activeMenu: '/wms/warehouse/warehouse' },

	    }
	  ]
	},
  {
	  path: '/wms/inbound/inbounds',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['inbound:inbound:add'],
	  children: [
	    {
	      path: 'inboundadd', // 修改为相对路径
	      component: () => import('@/views/wms/inbound/inbound/inboundadd'),
	      name: 'inboundadd',
	      meta: { title: '入库管理添加', activeMenu: '/wms/inbound/inbound' },

	    }
	  ]
	},
  {
	  path: '/wms/inbound/inbounds',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['inbound:inbound:edit'],
	  children: [
	    {
	      path: 'inboundupdate', // 修改为相对路径
	      component: () => import('@/views/wms/inbound/inbound/inboundadd'),
	      name: 'inboundupdate',
	      meta: { title: '入库管理修改', activeMenu: '/wms/inbound/inbound' },

	    }
	  ]
	},
  {
	  path: '/wms/inbound/inbounds',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['inbound:inbound:list'],
	  children: [
	    {
	      path: 'find', // 修改为相对路径
	      component: () => import('@/views/wms/inbound/inbound/index'),
	      name: 'find',
	      meta: { title: '入库管理', activeMenu: '/wms/inbound/inbound' },

	    }
	  ]
	},
	//新增出库
	{
	  path: '/wms/outbound/outbound',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['outbound:outbound:index'],
	  children: [
	    {
	      path: 'outboundadd', // 修改为相对路径
	      component: () => import('@/views/wms/outbound/outbound/outboundadd.vue'),
	      name: 'outboundadd',
	      meta: { title: '出库新增', activeMenu: '/wms/outbound/outbound' },
	    }
	  ]
	},
	{
	  path: '/wms/outbound/outbound',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['outbound:outbound:index'],
	  children: [
	    {
	      path: 'index', // 修改为相对路径
	      component: () => import('@/views/wms/outbound/outbound/index.vue'),
	      name: 'index',
	      meta: { title: '出库管理', activeMenu: '/wms/outbound/outbound' },
	    }
	  ]
	},
	{
	  path: '/wms/warehouse/warehouse',
	  component: Layout,
	  hidden: true,
	  name: 'index',
	  permissions: ['warehouse:warehouse:index'],
	  children: [
	    {
	      path: 'index', // 修改为相对路径
	      component: () => import('@/views/wms/warehouse/warehouse/index.vue'),
	      name: 'index',
	      meta: { title: '仓库管理', activeMenu: '/wms/warehouse/waerhouse' },
	    }
	  ]
	},
  {
    path: '/wms/message/message',
    component: Layout,
    hidden: true,
    name: 'index',
    permissions: ['message:message:list'],
    children: [
      {
        path: 'find', // 修改为相对路径
        component: () => import('@/views/wms/message/message/index.vue'),
        name: 'find',
        meta: { title: '系统消息', activeMenu: '/wms/message/message' },

      }
    ]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})


